namespace UnitTests.Foundation
{
    using System;
    using System.Collections.Generic;
    using System.Collections.Specialized;
    using System.IO;
    using System.Web;
    using Moq;

    public class WebTestContext : TestContext
    {
        public WebTestContext()
        {
            HttpContextMock = new Mock<HttpContextBase>();
            HttpContextMock.SetupAllProperties();

            RequestMock = new Mock<HttpRequestBase>();
            var form = new NameValueCollection();
            var queryString = new NameValueCollection();
            var requestCookies = new HttpCookieCollection();
            RequestMock.SetupGet(mock => mock.Form).Returns(() => form);
            RequestMock.SetupGet(mock => mock.QueryString).Returns(() => queryString);
            RequestMock.SetupGet(mock => mock.Cookies).Returns(() => requestCookies);
            RequestMock.SetupGet(mock => mock.Path).Returns("somePage.aspx");

            ResponseMock = new Mock<HttpResponseBase>();
            TextWriter outputWriter = new StringWriter();
            var responseCookies = new HttpCookieCollection();
            ResponseMock.SetupGet(mock => mock.Output).Returns(outputWriter);
            ResponseMock.SetupGet(mock => mock.Cookies).Returns(responseCookies);

            var items = new Dictionary<object, object>();
            HttpContextMock.SetupGet(context => context.Request).Returns(RequestMock.Object);
            HttpContextMock.SetupGet(context => context.Response).Returns(ResponseMock.Object);
            HttpContextMock.SetupGet(context => context.Items).Returns(items);
            HttpContextMock.SetupProperty(context => context.Handler);
        }

        public Mock<HttpRequestBase> RequestMock { get; set; }

        public Mock<HttpResponseBase> ResponseMock { get; set; }

        public Mock<HttpContextBase> HttpContextMock { get; set; }
    }
}